package a07_二叉树;

/**
 * <p>
 * a10_二叉树的最小深度复习0
 * </p>
 *
 * @author flyduck
 * @since 2024/12/26
 */
public class a10_二叉树的最小深度复习0 {

    //
    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int leftDepth = minDepth(root.left);
        int rightDepth = minDepth(root.right);
        if(leftDepth == 0){
            return rightDepth + 1;
        }else if(rightDepth == 0){
            return leftDepth + 1;
        }else {
            return Math.min(leftDepth, rightDepth) + 1;
        }
    }
}
